package com.shigu.activity.action;

import com.shigu.MallResponse;
import com.shigu.PageResponse;
import com.shigu.activity.api.ActivityGoodsService;
import com.shigu.activity.bo.ModifyLimitGoodsRequest;
import com.shigu.activity.bo.SetLimitGoodsRequest;
import com.shigu.activity.vo.LimitGoodsListVo;
import com.shigu.exceptions.AdminException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("adminjson")
public class ActivityAdminGoodsController {

    @Resource(name = "activityGoodsServiceImpl")
    ActivityGoodsService activityGoodsService;

    @RequestMapping("setLimitGoods")
    @ResponseBody
    public MallResponse setLimitGoods(SetLimitGoodsRequest request) throws AdminException {
        activityGoodsService.setLimitGoods(request.getGoodsCode(),Integer.valueOf(request.getNum()),
                request.getWeight());
        return new MallResponse().success();
    }

    @RequestMapping("modifyLimitGoods")
    @ResponseBody
    public MallResponse modifyLimitGoods(ModifyLimitGoodsRequest request) throws AdminException {
        activityGoodsService.modifyLimitGoods(request.getGoodsCode(),Integer.valueOf(request.getNum()),
                request.getWeight());
        return new MallResponse().success();
    }


    @RequestMapping("deleteLimitGoods")
    @ResponseBody
    public MallResponse deleteLimitGoods(Long goodsCode) throws AdminException {
        activityGoodsService.deleteLimitGoods(goodsCode);
        return new MallResponse().success();
    }

    @RequestMapping("getLimitGoodsList")
    @ResponseBody
    public PageResponse<LimitGoodsListVo> getLimitGoodsList(){
        return activityGoodsService.getLimitGoodsList().success();
    }
}
